//主从表tab选项卡标志位
var A013B7_Tab_Flag = -1;
//选择某一行
var A013B7_select_t_sub_user_rowId = "";
//按钮事件新增或编辑
var A013B7_type = "";
//其他页面传到本页面参数
var A013B7_param = {};
//table选中数据，如无则默认第一条
var A013B7_rowCheckData = null;

/*定义查询条件变量*/
/*declare query param begin*/

/*declare query param end*/

/*定义下拉框集合定义*/
/*declare select options begin*/
var A013B7_ary_SUB_ID = null;
/*declare select options end*/

/*绑定show监听事件*/
if(A013B7_Tab_Flag == "-1"){
	var n = Get_RandomDiv("A013B7","");
	$(n).bind("show", function(objTag){
		A013B7_Adjust_Sub_Sequ();
		if(A013B7_Tab_Flag > 0)
			A013B7_adjust_tab();		
	});
}

//设置主从表div顺序
function A013B7_Adjust_Sub_Sequ(){
	var temSubDivs = $("#content-main").find("div[data-id]");
	var MainDiv = $(Get_RandomDiv("A013B7",""));
	for(i = 0; i < temSubDivs.length; i++) {
		if(A013B7_Is_Sub_Div(temSubDivs[i].id)){
			$(temSubDivs[i]).before($(MainDiv));
			break;
		}
	}
}

//主从表传递参数
function A013B7_param_set(){
	/*Main Subsuv Table Param Begin*/
	
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function A013B7_t_sub_user_biz_start(inputparam) {
	layer.close(ly_index);
	A013B7_param = inputparam;
	//主从表传递参数
	A013B7_param_set();	
    /*biz begin*/
    var inputdata = {        "param_name": "N01_t_sub_power$SUB_ID",        "session_id": session_id,        "login_id": login_id    };    ly_index = layer.load();    get_ajax_baseurl(inputdata, "A013B7_get_N01_t_sub_power$SUB_ID");	
    /*biz end*/
}

/*业务函数步骤*/
/*biz step begin*/
function A013B7_format_SUB_ID(value, row, index) {    var objResult = value;    for(i = 0; i < A013B7_ary_SUB_ID.length; i++) {        var obj = A013B7_ary_SUB_ID[i];        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {            objResult = obj[GetLowUpp("cn_name")];            break;        }    }    return objResult;}function A013B7_get_N01_t_sub_power$SUB_ID(input) {    layer.close(ly_index);    //查询失败    if (Call_QryResult(input.N01_t_sub_power$SUB_ID) == false)        return false;    A013B7_ary_SUB_ID = input.N01_t_sub_power$SUB_ID;    A013B7_init_t_sub_user();}
/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

/*find qry fun end*/

/*页面结束*/
function A013B7_page_end(){
	A013B7_adjust_tab();
}

//接口用户信息显示列定义
var A013B7_t_sub_user = [
	{ 
		checkbox:true
	},
	/*table column begin*/
    {        title: '主键',        field: 'MAIN_ID',        sortable: true,        visible: false    },    {        title: '应用平台信息',        field: 'SUB_ID',        sortable: true        ,formatter: A013B7_format_SUB_ID    },    {        title: '用户名称',        field: 'SUB_USERNAME',        sortable: true        ,formatter: set_s_decode    },    {        title: '用户授权码',        field: 'SUB_USERCODE',        sortable: true        ,formatter: set_s_decode    },    {        title: '有效期限',        field: 'LIMIT_DATE',        sortable: true        ,formatter: set_time_decode    },    {        title: '备注',        field: 'S_DESC',        sortable: true        ,formatter: set_s_decode    },    {        title: '系统时间',        field: 'CREATE_DATE',        sortable: true        ,formatter: set_time_decode    }	
	/*table column end*/
];

//页面初始化
function A013B7_init_t_sub_user() {
	$(window).resize(function () {
		  $('#A013B7_t_sub_user_Events').bootstrapTable('resetView');
	});
	//接口用户信息查询条件初始化设置
	/*query conditions init begin*/
	
    /*query conditions init end*/
	
	$('#A013B7_btn_t_sub_user_query').click();
}

//查询接口
function A013B7_t_sub_user_query() {
    $('#A013B7_t_sub_user_Events').bootstrapTable("removeAll");
	//以下为特殊字段列表查询，无特殊字段时不需要
	var inputdata = {
		"param_name": "N01_sel_t_sub_user",
		"session_id": session_id,
		"login_id": login_id
		/*传递查询条件变量*/
        /*get query param begin*/
		
        /*get query param end*/
	};
	ly_index = layer.load();
	get_ajax_baseurl(inputdata, "A013B7_get_N01_sel_t_sub_user");
}

//查询结果
function A013B7_get_N01_sel_t_sub_user(input) {
	layer.close(ly_index);
	//查询失败
    if (Call_QryResult(input.N01_sel_t_sub_user) == false)
        return false;
    A013B7_rowCheckData = null;
    //调整table各列宽度
    $.each(A013B7_t_sub_user, function (i, obj) {
		if(obj.title != undefined){
			obj.width = obj.title.length * 14 + 37;
		}
	});
    
	var s_data = input.N01_sel_t_sub_user;
    if(s_data.length > 0)
    	A013B7_rowCheckData = s_data[0];    
    A013B7_select_t_sub_user_rowId = "";
    A013B7_Tab_Flag = 0;
    $('#A013B7_t_sub_user_Events').bootstrapTable('destroy');
    $("#A013B7_t_sub_user_Events").bootstrapTable({
        uniqueId: 'main_id',
        search: !0,
        pagination: !0,
        showRefresh: !0,
        showToggle: !0,
        showColumns: !0,
        iconSize: "outline",
        onClickRow: function (row, $element) {
            // 判断是否已选中
            if ($($element).hasClass("changeColor")) {
                $('#A013B7_t_sub_user_Events').find("tr.changeColor").removeClass('changeColor');
                A013B7_select_t_sub_user_rowId = "";
            }
            else {
                // 未点击则，为当前行添加 class='changeColor'
                $('#A013B7_t_sub_user_Events').find("tr.changeColor").removeClass('changeColor');
                $($element).addClass('changeColor');                　
                A013B7_select_t_sub_user_rowId = $element.attr('data-index');
                
                //设置子表查询条件
                /*set child table qry begin*/
                
                $($("#A013B7_TAB_MAIN").find(".active")[0]).click();
                /*set child table qry end*/
            }
        },
		onDblClickRow: function (row){
			if(A013B7_param.hasOwnProperty("target_name"))
			{
				$("#"+A013B7_param["target_id"]).val(eval("row."+A013B7_param["sourc_id"].toUpperCase()));
				$("#"+A013B7_param["target_name"]).val(s_decode(eval("row."+A013B7_param["sourc_name"].toUpperCase())));				
				layer.close(A013B7_param["ly_index"]);
			}
		},
        toolbar: "#A013B7_t_sub_user_Toolbar",
        columns: A013B7_t_sub_user,
        data: s_data,
        pageNumber: 1,
        pageSize: 10, // 每页的记录行数（*）
        pageList: [10,50,100,1000,2000], // 可供选择的每页的行数（*）
        icons: {
            refresh: "glyphicon-repeat",
            toggle: "glyphicon-list-alt",
            columns: "glyphicon-list"
        },
        onPostBody:function(){
        	if(s_data.length != 0)
            	A013B7_page_end();
        }
    });
    
    //子表数据查询动作
    /*child table data begin*/
    
    /*child table data end*/
}

//刷新按钮
$('#A013B7_btn_t_sub_user_refresh').click(function () {
	/*重置查询条件变量*/
	/*refresh query param begin*/

	/*refresh query param end*/

	/*重置下拉框集合定义*/
	/*refresh select options begin*/
    B013B7_ary_SUB_ID = null;
	/*refresh select options end*/
	
	/*页面重置重新加载*/
	/*biz begin*/
    var inputdata = {        "param_name": "N01_t_sub_power$SUB_ID",        "session_id": session_id,        "login_id": login_id    };    ly_index = layer.load();    get_ajax_baseurl(inputdata, "A013B7_get_N01_t_sub_power$SUB_ID");	
    /*biz end*/
})

//查询按钮
$('#A013B7_btn_t_sub_user_query').click(function () {
	/*设置查询条件变量*/
    /*set query param begin*/
	
    /*set query param end*/
	A013B7_t_sub_user_query();
})

//vue回调
function A013B7_t_sub_user_call_vue(objResult){
	//选择某条记录或自动选择第一条
	if (A013B7_select_t_sub_user_rowId != "") 
		A013B7_rowCheckData = $("#A013B7_t_sub_user_Events").bootstrapTable('getData')[A013B7_select_t_sub_user_rowId];
	
	if(index_subhtml == "t_sub_user_$.vue")
	{
		var n = Get_RandomDiv("B013B7",objResult);	
		layer.open({
			type: 1,
	        area: ['1100px', '600px'],
	        fixed: false, //不固定
	        maxmin: true,
	        content: $(n),
	        success: function(layero, index){
				var inputdata = {"type":A013B7_type,"ly_index":index};
				if(A013B7_param.hasOwnProperty("hidden_find")){
					inputdata["hidden_find"] = "1";
				}				
				/*查询条件参数传递至子页面,初次加载*/
				/*Send One FindSelect param bgein*/
					
				/*Send One FindSelect param end*/
				
	        	loadScript_hasparam("dev_vue/t_sub_user_$.js","B013B7_t_sub_user_biz_start",inputdata);
	        },
			end: function(){
				$(n).hide();
			}
	    });
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
	
	/*get find subvue end*/
	
	/*tab页显示子页面*/
	/*get tab subvue begin*/

	/*get tab subvue end*/
}

//新增按钮
$("#A013B7_btn_t_sub_user_add").click(function () {
	A013B7_type = "add";
	index_subhtml = "t_sub_user_$.vue";
	if(loadHtmlSubVueFun("dev_vue/t_sub_user_$.vue","A013B7_t_sub_user_call_vue") == true){
		var n = Get_RandomDiv("B013B7","");
		layer.open({
			type: 1,
			area: ['1100px', '600px'],
			fixed: false, //不固定
			maxmin: true,
			content: $(n),
			success: function(layero, index){
				B013B7_param["type"] = A013B7_type;
				B013B7_param["ly_index"]= index;
				if(A013B7_param.hasOwnProperty("hidden_find")){
					B013B7_param["hidden_find"] = "1";
				}
				/*查询条件参数传递至子页面,再次加载*/
			    /*Send Two FindSelect param bgein*/
				
				/*Send Two FindSelect param end*/

				B013B7_clear_edit_info();
			},
			end: function(){
				B013B7_clear_validate();
				$(n).hide();
			}
		});
	}
})

//编辑按钮
$("#A013B7_btn_t_sub_user_edit").click(function () {
	if (A013B7_select_t_sub_user_rowId != "") {
		A013B7_type = "edit";
		index_subhtml = "t_sub_user_$.vue";
		if(loadHtmlSubVueFun("dev_vue/t_sub_user_$.vue","A013B7_t_sub_user_call_vue") == true){
			var n = Get_RandomDiv("B013B7","");
			layer.open({
				type: 1,
				area: ['1100px', '600px'],
				fixed: false, //不固定
				maxmin: true,
				content: $(n),
				success: function(layero, index){
					B013B7_param["type"] = A013B7_type;
					B013B7_param["ly_index"] = index;
					if(A013B7_param.hasOwnProperty("hidden_find")){
						B013B7_param["hidden_find"] = "1";
					}
					B013B7_clear_edit_info();
					B013B7_get_edit_info();
				},
				end: function(){
					B013B7_clear_validate();
					$(n).hide();
				}
			});
		}
	} else {
		swal({
            title: "提示信息",
            text: "无法修改记录，请选择正确记录修改!"
        });
    }
})

//删除按钮
$('#A013B7_btn_t_sub_user_delete').click(function () {
	//单行选择
	var rowData = $("#A013B7_t_sub_user_Events").bootstrapTable('getData')[A013B7_select_t_sub_user_rowId];
	//多行选择
	var rowDatas = A013B7_sel_row_t_sub_user();
	if (A013B7_select_t_sub_user_rowId != "" || rowDatas.length > 0) {
    	swal({
            title: "告警",
            text: "确认要删除吗?删除数据将无法恢复!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            closeOnConfirm: false
        },
		function () {
        	if(rowDatas.length > 0)
        	{
	        	$.each(rowDatas, function (i, obj) {
					var delete_main_id = obj.MAIN_ID;
					var inputdata = {
						"param_name": "N01_del_t_sub_user",
						"session_id": session_id,
						"login_id": login_id,
						"param_value1": delete_main_id
					};
					ly_index = layer.load();
					get_ajax_baseurl(inputdata, "A013B7_N01_del_t_sub_user");
	        	});
        	}
        	else
        	{
        		var delete_main_id = rowData["MAIN_ID"];
				var inputdata = {
					"param_name": "N01_del_t_sub_user",
					"session_id": session_id,
					"login_id": login_id,
					"param_value1": delete_main_id
				};
				ly_index = layer.load();
				get_ajax_baseurl(inputdata, "A013B7_N01_del_t_sub_user");
        	}
		}); 
    } else {
    	swal({
            title: "提示信息",
            text: "无法删除记录，请选择正确记录删除!"
        });
    }
})

//删除结果
function A013B7_N01_del_t_sub_user(input) {
	layer.close(ly_index);
	if(Call_OpeResult(input.N01_del_t_sub_user) == true)
		A013B7_t_sub_user_query();
}

//特殊字符串数据解码
function set_s_decode(value, row, index) {
    return s_decode(value);
}

//时间数据解码
function set_time_decode(value, row, index) {
  var timeResult = s_decode(value);
  return timeResult.replace("T"," ");
}

//主从表选项卡动态添加
function A013B7_adjust_tab(){
	if(typeof($("#A013B7_TAB_MAIN")[0]) != "undefined" && $("#A013B7_TAB_MAIN")[0].length != 0){
		A013B7_Tab_Flag = 1;
		$(Get_RDivNoBuild("A013B7","")).find(".wrapper-content").css("padding","20px 20px 0px 20px");
		$(Get_RDivNoBuild("A013B7","")).find(".ibox").css("margin-bottom","0px");
		$(Get_RDivNoBuild("A013B7","")).find(".ibox-content").css("padding","15px 20px 0px");		
		$($("#A013B7_TAB_MAIN").find(".active")[0]).click();
	}
}

/*tab选项卡按钮点击事件*/
/*Tab Click Fun Begin*/
//隐藏tab页选项卡function A013B7_hide_tab_fun(){    var n = null;}//判断是否sub子项div页面function A013B7_Is_Sub_Div(temDivId){    if(temDivId.indexOf("XX$TTT") == 0)        return false;    return false;}
/*Tab Click Fun End*/

function A013B7_show_tab_fun(inputUrl,inputrandom,temPar){
	index_subhtml = inputUrl;
	random_subhtml = inputrandom;
	if(loadHtmlSubVueFun("dev_vue/"+inputUrl,"A013B7_t_sub_user_call_vue") == true){
		var n = Get_RandomDiv(inputrandom,"");
		$(n).show();
		var rowData = null;
		//选择某条记录或自动选择第一条并传递参数
		if (A013B7_select_t_sub_user_rowId != "") 
			rowData = $("#A013B7_t_sub_user_Events").bootstrapTable('getData')[A013B7_select_t_proc_name_rowId];
		else
			rowData = A013B7_rowCheckData;
		//$("#A013B7_t_sub_user_Events").bootstrapTable('getData')[0];
		if(rowData != null){
			var temFlag = true;
			$.each(temPar, function (i, obj) {
				if(eval(inputrandom+"_param.hasOwnProperty(\""+obj.target_id+"\")") && eval(inputrandom+"_param[\""+obj.target_id+"\"]").toString() == rowData[obj.sourc_id].toString())
					temFlag = false;
				else
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \""+rowData[obj.sourc_id]+"\"");
			});
			if(temFlag){
				//传递子页面隐藏find功能
				eval(inputrandom+"_param[\"hidden_find\"] = \"1\"");
				//参数传递并赋值
				eval(inputrandom+"_param_set()");
				var tbName = inputUrl.substring(0,inputUrl.indexOf(".vue"));		
				$("#"+inputrandom+"_btn_"+tbName+"_query").click();
			}
		}
		else{
			$.each(temPar, function (i, obj) {
				if(obj.sourc_id.toUpperCase() == "MAIN_ID")
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \"-999\"");
				else
					eval(inputrandom+"_param[\""+obj.target_id+"\"] = \"\"");
			});
			//传递子页面隐藏find功能
			eval(inputrandom+"_param[\"hidden_find\"] = \"1\"");
			//参数传递并赋值
			eval(inputrandom+"_param_set()");
			var tbName = inputUrl.substring(0,inputUrl.indexOf(".vue"));		
			$("#"+inputrandom+"_btn_"+tbName+"_query").click();		
		}
	}
}

//清除 查找框
function A013B7_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//选择多行数据进行业务操作
function A013B7_sel_row_t_sub_user(){
	//获得选中行
	var checkedbox= $("#A013B7_t_sub_user_Events").bootstrapTable('getSelections'); 
	//将选中行数据转成jsonStr
	var jsonStr=JSON.stringify(checkedbox);
	//将jsonStr转成jsonObject对象	 
	var jsonObject=jQuery.parseJSON(jsonStr);
	return jsonObject;
	//接着就可以遍历jsonObject数组对象，取出并操作数据
	//alert(jsonObject);
}